Eclipse Platform
Pre-release 3.0

org.eclipse.ui.editors.text
Class TextFileDocumentProvider

java.lang.Object
  extended byorg.eclipse.ui.editors.text.TextFileDocumentProvider
All Implemented Interfaces:
IDocumentProvider, IDocumentProviderExtension, IDocumentProviderExtension2, IDocumentProviderExtension3, IStorageDocumentProvider

public class TextFileDocumentProvider
extends Object
implements IDocumentProvider, IDocumentProviderExtension, IDocumentProviderExtension2, IDocumentProviderExtension3, IStorageDocumentProvider

Since:
3.0

Nested Class Summary
protected static class TextFileDocumentProvider.DocumentProviderOperation
          Opertion created by the document provider and to be executed by the providers runnable context.
protected  class TextFileDocumentProvider.FileBufferListener
           
protected static class TextFileDocumentProvider.FileInfo
           
protected static class TextFileDocumentProvider.NullProvider
           
 
Constructor Summary
TextFileDocumentProvider()
           
TextFileDocumentProvider(IDocumentProvider parentProvider)
           
 
Method Summary
 void aboutToChange(Object element)
          Informs this document provider about upcoming changes of the given element.
 void addElementStateListener(IElementStateListener listener)
          Adds the given element state listener to this document provider.
 boolean canSaveDocument(Object element)
          Returns whether the document provided for the given element differs from its original state which would required that it be saved.
 void changed(Object element)
          Informs this document provider that the given element has been changed.
protected  void commitFileBuffer(IProgressMonitor monitor, TextFileDocumentProvider.FileInfo info, boolean overwrite)
           
 void connect(Object element)
          Connects the given element to this document provider.
protected  IAnnotationModel createAnnotationModel(IFile file)
           
protected  TextFileDocumentProvider.FileInfo createEmptyFileInfo()
           
protected  void createFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document)
           
protected  TextFileDocumentProvider.FileInfo createFileInfo(Object element)
           
protected  TextFileDocumentProvider.DocumentProviderOperation createSaveOperation(Object element, IDocument document, boolean overwrite)
           
 void disconnect(Object element)
          Disconnects the given element from this document provider.
protected  void disposeFileInfo(Object element, TextFileDocumentProvider.FileInfo info)
           
protected  void executeOperation(TextFileDocumentProvider.DocumentProviderOperation operation, IProgressMonitor monitor)
          Executes the given operation in the providers runnable context.
protected  void fireElementStateChangeFailed(Object element)
           
protected  void fireElementStateChanging(Object element)
           
 IAnnotationModel getAnnotationModel(Object element)
          Returns the annotation model for the given element.
protected  Iterator getConnectedElementsIterator()
           
 String getDefaultEncoding()
          Returns the default character encoding used by this provider.
 IDocument getDocument(Object element)
          Returns the document for the given element.
protected  Iterator getElements(IFileBuffer file)
          Returns an iterator for all the elements that are connected to this file buffer.
 String getEncoding(Object element)
          Returns the character encoding for the given element, or null if the element is not managed by this provider.
protected  TextFileDocumentProvider.FileInfo getFileInfo(Object element)
           
protected  Iterator getFileInfosIterator()
           
 long getModificationStamp(Object element)
          Returns the modification stamp of the given element.
protected  IRunnableContext getOperationRunner(IProgressMonitor monitor)
          Returns the runnable context for this document provider.
protected  IDocumentProvider getParentProvider()
          Returns the parent document provider.
 IProgressMonitor getProgressMonitor()
          Returns this providers progress monitor.
 IStatus getStatus(Object element)
          Returns the status of the given element.
 long getSynchronizationStamp(Object element)
          Returns the time stamp of the last synchronization of the given element and it's provided document.
protected  File getSystemFile(TextFileDocumentProvider.FileInfo info)
           
protected  void handleCoreException(CoreException exception, String message)
          Defines the standard procedure to handle CoreExceptions.
 boolean isDeleted(Object element)
          Returns whether the given element has been deleted.
 boolean isModifiable(Object element)
          Returns whether the document provider thinks that the given element can persistently be modified.
 boolean isReadOnly(Object element)
          Returns whether the document provider thinks that the given element is read-only.
 boolean isStateValidated(Object element)
          Returns whether the state of the given element has been validated.
 boolean isSynchronized(Object element)
          Returns whether the information provided for the given element is in sync with the element.
protected  boolean isSystemFileReadOnly(TextFileDocumentProvider.FileInfo info)
           
 boolean mustSaveDocument(Object element)
          Returns whether the document provided for the given element must be saved.
 void removeElementStateListener(IElementStateListener listener)
          Removes the given element state listener from this document provider.
 void resetDocument(Object element)
          Resets the given element's document to its last saved state.
 void saveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
          Saves the given document provided for the given element.
 void setCanSaveDocument(Object element)
          Marks the document managed for the given element as saveable.
 void setEncoding(Object element, String encoding)
          Sets the encoding for the given element.
 void setParentDocumentProvider(IDocumentProvider parentProvider)
           
 void setProgressMonitor(IProgressMonitor progressMonitor)
          Sets this providers progress monitor.
 void synchronize(Object element)
          Synchronizes the document provided for the given element with the given element.
 void updateStateCache(Object element)
          Updates the state cache for the given element.
 void validateState(Object element, Object computationContext)
          Validates the state of the given element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFileDocumentProvider

public TextFileDocumentProvider()

TextFileDocumentProvider

public TextFileDocumentProvider(IDocumentProvider parentProvider)
Method Detail

setParentDocumentProvider

public final void setParentDocumentProvider(IDocumentProvider parentProvider)

getParentProvider

protected final IDocumentProvider getParentProvider()
Returns the parent document provider.

Returns:
the parent document provider

getOperationRunner

protected IRunnableContext getOperationRunner(IProgressMonitor monitor)
Returns the runnable context for this document provider.

Returns:
the runnable context for this document provider

executeOperation

protected void executeOperation(TextFileDocumentProvider.DocumentProviderOperation operation,
                                IProgressMonitor monitor)
                         throws CoreException
Executes the given operation in the providers runnable context.

Parameters:
operation - the operation to be executes
monitor - the progress monitor
Throws:
CoreException - the operation's core exception

connect

public void connect(Object element)
             throws CoreException
Description copied from interface: IDocumentProvider
Connects the given element to this document provider. This tells the provider that caller of this method is interested to work with the document provided for the given domain model element. By counting the invocations of this method and disconnect(Object) this provider can assume to know the correct number of clients working with the document provided for that domain model element.

The given element must not be null.

Specified by:
connect in interface IDocumentProvider
Parameters:
element - the element
Throws:
CoreException - if the textual representation or the annotation model of the element could not be created

createEmptyFileInfo

protected TextFileDocumentProvider.FileInfo createEmptyFileInfo()

createFileInfo

protected TextFileDocumentProvider.FileInfo createFileInfo(Object element)
                                                    throws CoreException
Throws:
CoreException

createAnnotationModel

protected IAnnotationModel createAnnotationModel(IFile file)

disconnect

public void disconnect(Object element)
Description copied from interface: IDocumentProvider
Disconnects the given element from this document provider. This tells the provider that the caller of this method is no longer interested in working with the document provided for the given domain model element. By counting the invocations of connect(Object) and of this method this provider can assume to know the correct number of clients working with the document provided for that domain model element.

The given element must not be null.

Specified by:
disconnect in interface IDocumentProvider
Parameters:
element - the element

disposeFileInfo

protected void disposeFileInfo(Object element,
                               TextFileDocumentProvider.FileInfo info)

getElements

protected Iterator getElements(IFileBuffer file)
Returns an iterator for all the elements that are connected to this file buffer.

Parameters:
file - the file buffer
Returns:
an iterator for all elements connected with the given file buffer

getDocument

public IDocument getDocument(Object element)
Description copied from interface: IDocumentProvider
Returns the document for the given element. Usually the document contains a textual presentation of the content of the element, or is the element itself.

Specified by:
getDocument in interface IDocumentProvider
Parameters:
element - the element, or null
Returns:
the document, or null if none

resetDocument

public void resetDocument(Object element)
                   throws CoreException
Description copied from interface: IDocumentProvider
Resets the given element's document to its last saved state. Element state listeners are notified both before (elementContentAboutToBeReplaced) and after (elementContentReplaced) the content is changed.

Specified by:
resetDocument in interface IDocumentProvider
Parameters:
element - the element, or null
Throws:
CoreException

saveDocument

public final void saveDocument(IProgressMonitor monitor,
                               Object element,
                               IDocument document,
                               boolean overwrite)
                        throws CoreException
Description copied from interface: IDocumentProvider
Saves the given document provided for the given element.

Specified by:
saveDocument in interface IDocumentProvider
Parameters:
monitor - a progress monitor to report progress and request cancelation
element - the element, or null
document - the document
overwrite - indicates whether overwrite should be performed while saving the given element if necessary
Throws:
CoreException - if document could not be stored to the given element

createSaveOperation

protected TextFileDocumentProvider.DocumentProviderOperation createSaveOperation(Object element,
                                                                                 IDocument document,
                                                                                 boolean overwrite)
                                                                          throws CoreException
Throws:
CoreException

commitFileBuffer

protected void commitFileBuffer(IProgressMonitor monitor,
                                TextFileDocumentProvider.FileInfo info,
                                boolean overwrite)
                         throws CoreException
Throws:
CoreException

createFileFromDocument

protected void createFileFromDocument(IProgressMonitor monitor,
                                      IFile file,
                                      IDocument document)
                               throws CoreException
Throws:
CoreException

getModificationStamp

public long getModificationStamp(Object element)
Description copied from interface: IDocumentProvider
Returns the modification stamp of the given element.

Specified by:
getModificationStamp in interface IDocumentProvider
Parameters:
element - the element
Returns:
the modification stamp of the given element

getSynchronizationStamp

public long getSynchronizationStamp(Object element)
Description copied from interface: IDocumentProvider
Returns the time stamp of the last synchronization of the given element and it's provided document.

Specified by:
getSynchronizationStamp in interface IDocumentProvider
Parameters:
element - the element
Returns:
the sysnchronization stamp of the given element

isDeleted

public boolean isDeleted(Object element)
Description copied from interface: IDocumentProvider
Returns whether the given element has been deleted.

Specified by:
isDeleted in interface IDocumentProvider
Parameters:
element - the element
Returns:
true if the element has been deleted

mustSaveDocument

public boolean mustSaveDocument(Object element)
Description copied from interface: IDocumentProvider
Returns whether the document provided for the given element must be saved.

Specified by:
mustSaveDocument in interface IDocumentProvider
Parameters:
element - the element, or null
Returns:
true if the document must be saved, and false otherwise (including the element is null)

canSaveDocument

public boolean canSaveDocument(Object element)
Description copied from interface: IDocumentProvider
Returns whether the document provided for the given element differs from its original state which would required that it be saved.

Specified by:
canSaveDocument in interface IDocumentProvider
Parameters:
element - the element, or null
Returns:
true if the document can be saved, and false otherwise (including the element is null)

getAnnotationModel

public IAnnotationModel getAnnotationModel(Object element)
Description copied from interface: IDocumentProvider
Returns the annotation model for the given element.

Specified by:
getAnnotationModel in interface IDocumentProvider
Parameters:
element - the element, or null
Returns:
the annotation model, or null if none

aboutToChange

public void aboutToChange(Object element)
Description copied from interface: IDocumentProvider
Informs this document provider about upcoming changes of the given element. The changes might cause change notifications specific for the type of the given element. If this provider manages a document for the given element, the document provider must not change the document because of the notifications received after aboutToChange has been and before changed is called. In this case, it is assumed that the document is already up to date, e.g., a save operation is a typical case.

The concrete nature of the change notification depends on the concrete type of the given element. If the element is, e.g., an IResource the notification is a resource delta.

Specified by:
aboutToChange in interface IDocumentProvider
Parameters:
element - the element, or null

changed

public void changed(Object element)
Description copied from interface: IDocumentProvider
Informs this document provider that the given element has been changed. All notifications have been sent out. If this provider manages a document for the given element, the document provider must from now on change the document on the receipt of change notifications. The concrete nature of the change notification depends on the concrete type of the given element. If the element is, e.g., an IResource the notification is a resource delta.

Specified by:
changed in interface IDocumentProvider
Parameters:
element - the element, or null

addElementStateListener

public void addElementStateListener(IElementStateListener listener)
Description copied from interface: IDocumentProvider
Adds the given element state listener to this document provider. Has no effect if an identical listener is already registered.

Specified by:
addElementStateListener in interface IDocumentProvider
Parameters:
listener - the listener

removeElementStateListener

public void removeElementStateListener(IElementStateListener listener)
Description copied from interface: IDocumentProvider
Removes the given element state listener from this document provider. Has no affect if an identical listener is not registered.

Specified by:
removeElementStateListener in interface IDocumentProvider
Parameters:
listener - the listener

isReadOnly

public boolean isReadOnly(Object element)
Description copied from interface: IDocumentProviderExtension
Returns whether the document provider thinks that the given element is read-only. If this method returns true, saveDocument could fail. This method does not say anything about the document constructed from the given element. If the given element is not connected to this document provider, the return value is undefined. Document providers are allowed to use a cache to answer this question, i.e. there can be a difference between the "real" state of the element and the return value.

Specified by:
isReadOnly in interface IDocumentProviderExtension
Parameters:
element - the element
Returns:
true if the given element is read-only, false otherwise

isModifiable

public boolean isModifiable(Object element)
Description copied from interface: IDocumentProviderExtension
Returns whether the document provider thinks that the given element can persistently be modified. This is orthogonal to isReadOnly as read-only elements may be modifiable and writable elements may not be modifiable. If the given element is not connected to this document provider, the result is undefined. Document providers are allowed to use a cache to answer this question, i.e. there can be a difference between the "real" state of the element and the return value.

Specified by:
isModifiable in interface IDocumentProviderExtension
Parameters:
element - the element
Returns:
true if the given element is modifiable, false otherwise

validateState

public void validateState(Object element,
                          Object computationContext)
                   throws CoreException
Description copied from interface: IDocumentProviderExtension
Validates the state of the given element. This method may change the "real" state of the element. If using, it also updates the internal caches, so that this method may also change the results returned by isReadOnly and isModifiable. If the given element is not connected to this document provider, the effect is undefined.

Specified by:
validateState in interface IDocumentProviderExtension
Parameters:
element - the element
computationContext - the context in which the computation is performed, e.g., a SWT shell
Throws:
CoreException - if validating fails

isStateValidated

public boolean isStateValidated(Object element)
Description copied from interface: IDocumentProviderExtension
Returns whether the state of the given element has been validated.

Specified by:
isStateValidated in interface IDocumentProviderExtension
Parameters:
element - the element
Returns:
true if the state has been validated

updateStateCache

public void updateStateCache(Object element)
                      throws CoreException
Description copied from interface: IDocumentProviderExtension
Updates the state cache for the given element. This method may change the result returned by isReadOnly and isModifiable. If the given element is not connected to this document provider, the effect is undefined.

Specified by:
updateStateCache in interface IDocumentProviderExtension
Parameters:
element - the element
Throws:
CoreException - if validating fails

setCanSaveDocument

public void setCanSaveDocument(Object element)
Description copied from interface: IDocumentProviderExtension
Marks the document managed for the given element as saveable. I.e. canBeSaved(element) will return true afterwards.

Specified by:
setCanSaveDocument in interface IDocumentProviderExtension
Parameters:
element - the element

getStatus

public IStatus getStatus(Object element)
Description copied from interface: IDocumentProviderExtension
Returns the status of the given element.

Specified by:
getStatus in interface IDocumentProviderExtension
Parameters:
element - the element
Returns:
the status of the given element

synchronize

public void synchronize(Object element)
                 throws CoreException
Description copied from interface: IDocumentProviderExtension
Synchronizes the document provided for the given element with the given element. After that call getSynchronizationTimeStamp and getModificationTimeStamp return the same value.

Specified by:
synchronize in interface IDocumentProviderExtension
Parameters:
element - the element
Throws:
CoreException - if the synchronization could not be performed

setProgressMonitor

public void setProgressMonitor(IProgressMonitor progressMonitor)
Description copied from interface: IDocumentProviderExtension2
Sets this providers progress monitor.

Specified by:
setProgressMonitor in interface IDocumentProviderExtension2
Parameters:
progressMonitor -

getProgressMonitor

public IProgressMonitor getProgressMonitor()
Description copied from interface: IDocumentProviderExtension2
Returns this providers progress monitor.

Specified by:
getProgressMonitor in interface IDocumentProviderExtension2
Returns:
IProgressMonitor

isSynchronized

public boolean isSynchronized(Object element)
Description copied from interface: IDocumentProviderExtension3
Returns whether the information provided for the given element is in sync with the element.

Specified by:
isSynchronized in interface IDocumentProviderExtension3
Parameters:
element - the element
Returns:
true if the information is in sync with the element, false otherwise

getDefaultEncoding

public String getDefaultEncoding()
Description copied from interface: IStorageDocumentProvider
Returns the default character encoding used by this provider.

Specified by:
getDefaultEncoding in interface IStorageDocumentProvider
Returns:
the default character encoding used by this provider

getEncoding

public String getEncoding(Object element)
Description copied from interface: IStorageDocumentProvider
Returns the character encoding for the given element, or null if the element is not managed by this provider.

Specified by:
getEncoding in interface IStorageDocumentProvider
Parameters:
element - the element
Returns:
the encoding for the given element

setEncoding

public void setEncoding(Object element,
                        String encoding)
Description copied from interface: IStorageDocumentProvider
Sets the encoding for the given element. If encoding is null the workbench's character encoding should be used.

Specified by:
setEncoding in interface IStorageDocumentProvider
Parameters:
element - the element
encoding - the encoding to be used

handleCoreException

protected void handleCoreException(CoreException exception,
                                   String message)
Defines the standard procedure to handle CoreExceptions. Exceptions are written to the plug-in log.

Parameters:
exception - the exception to be logged
message - the message to be logged

getSystemFile

protected File getSystemFile(TextFileDocumentProvider.FileInfo info)

isSystemFileReadOnly

protected boolean isSystemFileReadOnly(TextFileDocumentProvider.FileInfo info)

getFileInfo

protected TextFileDocumentProvider.FileInfo getFileInfo(Object element)

getConnectedElementsIterator

protected Iterator getConnectedElementsIterator()

getFileInfosIterator

protected Iterator getFileInfosIterator()

fireElementStateChanging

protected void fireElementStateChanging(Object element)

fireElementStateChangeFailed

protected void fireElementStateChangeFailed(Object element)

Eclipse Platform
Pre-release 3.0

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.